import { createStore } from 'vuex'

export default createStore({
  state: {
    config: {},
		fMer: '',
		keepList: [],
  },
  mutations: {
    saveConfig(state, data) {
			state.config = data
		},
		saveFMer(state, data) {
			state.fMer = data
		},
		setKeepList(state, val) {
			console.log(val)
			if (typeof val.name !== 'string' ) {
				val.name.forEach(res => {
					let index = state.keepList.indexOf(res);
					console.log(index)
					if (val.type === 0) { // 新增
						if (index == -1) {
							state.keepList.push(res)
						}

					} else { // 删除
						if (index > -1) {
							state.keepList.splice(index, 1)
						}
					}

				})

			} else {

				let index = state.keepList.indexOf(val.name);
				if (val.type === 0) { // 新增
					if (index == -1) {
						state.keepList.push(val.name)
					}

				} else { // 删除
					if (index > -1) {
						state.keepList.splice(index, 1)
					}
				}

			}

			console.log(state.keepList)




		}
  },
  actions: {
  },
  modules: {
  },
  getters: {
		config: state => state.config,
	}
})
